package com.shujia.spark.mllib

import org.apache.spark.ml.classification.LogisticRegressionModel
import org.apache.spark.ml.linalg.Vectors
import org.apache.spark.sql.SparkSession

object Demo4UseModel {
  def main(args: Array[String]): Unit = {
    val spark: SparkSession = SparkSession
      .builder()
      .master("local")
      .appName("person")
      .config("spark.sql.shuffle.partitions", 1)
      .getOrCreate()

    import spark.implicits._

    /**
      * 使用已经保存好的模型
      *
      */

    //1、加载模型
    val model: LogisticRegressionModel = LogisticRegressionModel.load("data/person_model")

    //2、构建一个向量带入模型，预测结果

    /**
      * 0 1:4.6 2:3.0 3:2.2 4:90.8 5:64.3 6:53.1 7:81
      * 1 1:6.3 2:4.3 3:3.2 4:145.2 5:87.7 6:81.2 7:65
      */
    val y1: Double = model.predict(Vectors.dense(4.6, 3.0, 2.2, 90.8, 64.3, 53.1, 81))
    println(y1)

    val y2: Double = model.predict(Vectors.dense(6.3, 4.3, 3.2, 145.2, 87.7, 81.2, 65))
    println(y2)

  }

}
